package com.cn.web.servlet;

import java.io.IOException;
import java.util.List;

import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import com.cn.domain.Product;

public class TopServletListServlet extends BaseServlet {

	public void doGet(HttpServletRequest request, HttpServletResponse response)
			throws ServletException, IOException {
		doPost(request, response);
	}

	public void doPost(HttpServletRequest request, HttpServletResponse response)
			throws ServletException, IOException {
		
		String year = request.getParameter("year");
		String mouth = request.getParameter("mouth");
		System.out.println(year);
		System.out.println(mouth);
		List<Product> list = ps.getTopSaleList(year, mouth);
		response.setHeader("content-disposition", "attachment;filename=top.csv");
		response.setCharacterEncoding("GBK");
		for(Product p:list){
			response.getWriter().write(p.getId()+","+p.getPrice()+","+p.getName()+","+p.getCategory()+","+p.getNum()+","+p.getSaleSum()+"\r");
		}
	}

}
